import $http from '@/common/http.js'
import $store from '@/store/index.js'
/**
 * @description 查找会员列表
 */
export const queryMembers = async (cond = null) => {
  let service = 'srvretail_member_info_select'
  service = 'srvretail_member_info_custom_select'
  const url = `/retail/select/${service}`
  const req = {
    "serviceName": service,
    "colNames": ["*"],
    // "condition": [{
    //   colName:'member_state',
    //   ruleType:'ne',
    //   value:'挂失'
    // },
    // {
    //   colName:'member_state',
    //   ruleType:'ne',
    //   value:'禁用'
    // }],
    "page": {
      "pageNo": 1,
      "rownumber": 1000
    }
  }
  if (cond && cond.relation) {
    req.relation_condition = cond
  }else{
    queryIntegralSet()
  }
  const res = await $http.post(url, req)
  if (res?.data?.state === 'SUCCESS') {
    if (Array.isArray(cond) && cond.length > 0) {
      
    } else {
      $store.commit('SET_MEMBERS', res.data.data)
    }
    return res.data.data
  }
  return res.data
}
/**
 * @description 查询员工列表
 */
export const queryStaff = async () => {
  const url = `/retail/select/srvretail_store_staff_select`
  const req = {
    "serviceName": "srvretail_store_staff_select",
    "colNames": ["*"],
    "condition": [{
      'colName': 'staff_status',
      ruleType: 'eq',
      value: '在职'
    }],
    "page": {
      "pageNo": 1,
      "rownumber": 500
    }
  }

  const res = await $http.post(url, req)
  if (res?.data?.state === 'SUCCESS') {
    $store.commit('SET_STATE', {
      key: '$staffList',
      value: res.data.data,
      persistence: true
    })
    return res.data.data
  } else {
    // debugger
    // return await queryStaff()
  }
}

export const queryIntegralSet = async (store_no) => {
  const url = `/retail/select/srvretail_member_setup_select`
  const req = {
    "serviceName": "srvretail_member_setup_select",
    "condition": [{
      "colName": "store_no",
      "ruleType": "eq",
      "value": store_no || uni.getStorageSync('login_user_info')?.store_no
    }],
    "colNames": ["*"],
  }
  const res = await $http.post(url, req)
  console.log(res, '$integralSetting');
  if (Array.isArray(res?.data?.data) && res?.data?.data.length > 0) {
    $store.commit('SET_STATE', {
      key: '$integralSetting',
      value: res.data.data[0]
    })
    console.log(res.data.data[0], '$integralSetting');
    return res.data.data[0]
  }
}
